package com.gitee.ywj1352.kaishi.Test;

import org.junit.Test;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author wenjie.yang
 * @date 3/28/2020 9:59 AM
 */
public class TestingDemo2 {


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextDouble()) {// 注意，如果输入是多个测试用例，请通过while循环处理多个测试用例
            double v = in.nextDouble();
            sailSomething(v);
        }
    }


    public static void sailSomething(double jiagao) {
        TreeMap<Double, Integer> map = new TreeMap<>();
        for (int i = 1; i <= 10000; i++) {
            Double sum = jiagao * i;
            if (sum > 1) {
                String[] split = sum.toString().split("[.]");
                Integer zeng = Integer.valueOf(split[0]);
                BigDecimal bigDecimal = new BigDecimal(Double.valueOf("0." + split[1]));
                bigDecimal.setScale(19, BigDecimal.ROUND_HALF_DOWN);
                Double xiaoshu = bigDecimal.doubleValue();

                if (map.get(xiaoshu) == null) {
                    map.put(xiaoshu, zeng);
                }
            }
        }
        Map.Entry<Double, Integer> doubleIntegerEntry = map.lastEntry();
        Integer zong = doubleIntegerEntry.getKey() > 0.5 ? doubleIntegerEntry.getValue() + 1 : doubleIntegerEntry.getValue();
        Double v = zong / jiagao;
        String[] split = v.toString().split("[.]");
        Integer geshu = Integer.valueOf(split[0]);
        Double v1 = geshu * jiagao;

        String[] split1 = v1.toString().split("[.]");
        Integer zongjia = 0;
        if (Double.valueOf("0." + split1[1]) >= 0.5) {
            zongjia = Integer.valueOf(split1[0]) + 1;
        } else {
            zongjia = Integer.valueOf(split1[0]);
        }
        System.out.println(zongjia + " " + geshu + ":" + Double.valueOf(zongjia) / Double.valueOf(geshu));
    }


    @Test
    public void fun1() {//
        //[[1,0,0,1],[0,1,1,0],[0,1,1,1],[1,0,1,1]]
        int[][] arr = {{1, 0, 0, 1},
                {0, 1, 1, 0},
                {0, 1, 1, 1},
                {1, 0, 1, 1}};
        System.out.println(findCircleNum(arr));
    }
    /**
     * [[1,1,0,0],
     * [1,1,1,0],
     * [0,1,1,0]
     * [0,0,0,1]]
     * <p>
     * {{1, 0, 0, 1},
     * {0, 1, 1, 0},
     * {0, 1, 1, 1},
     * {1, 0, 1, 1}};
     *
     * @param M
     * @return
     */
    public int findCircleNum(int[][] M) {
        int count = 0;
        for (int i = 0; i < M.length; i++) {
            if (M[i][i] != 0) {
                count++;
                ganRan(M, i);
            }
        }

        return count;
    }

    public void ganRan(int[][] M, Integer J) {
        Queue<Integer> queue = new LinkedList<>();
        queue.add(J);
        while (J != null) {
            for (int i = 0; i < M.length; i++) {
                if (M[i][J] == 1 && M[J][i] == 1 && i != J) {
                    queue.add(i);
                    M[J][i] = 0;
                    M[i][J] = 0;
                }
            }
            M[J][J] = 0;
            J = queue.poll();
        }
    }

    @Test
    public void fun3() {
        String s = "ABCDEF";
        String[] permutation = permutation(s);
        System.out.println(list);
        System.out.println(permutation);
    }
    private Set<String> list = new HashSet<>();

    public String[] permutation(String s) {
        char[] arr = s.toCharArray();
        boolean[] dp = new boolean[arr.length];
        String S = "";
        int depth = 0;
        pdfs(arr, dp, S, depth);
        String[] strings = new String[list.size()];
        list.toArray(strings);
        return strings;
    }

    public void pdfs(char[] arr, boolean[] dp, String S, int depth) {
        if (depth == arr.length) {
            list.add(S);
            return;
        }
        for (int i = 0; i < dp.length; i++) {
            if (!dp[i]) {
                S = S + arr[i];
                dp[i] = true;
                depth++;
                pdfs(arr, dp, S, depth);
                dp[i] = false;
                depth--;
                S = S.substring(0, S.length() - 1);
            }
        }
    }

    @Test
    public void  fun19() throws ParseException {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
        Date parse = df.parse("2020-04-02T20:00:00.74+02:00");
        System.out.println(parse);
    }


}
